package com.example.mrzhou.lvmm.view.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.entity.surround.holiday.Holiday;
import com.example.mrzhou.lvmm.entity.surround.hotel.Hotel;
import com.example.mrzhou.lvmm.entity.surround.scenic.Scenic;
import com.example.mrzhou.lvmm.entity.surround.scenic.TickListBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MapActivity extends AppCompatActivity {

    @BindView(R.id.iv_map_back)
    ImageView ivMapBack;
    @BindView(R.id.map_mapview)
    MapView mapMapview;
    private BaiduMap baiduMap;

    private List<TickListBean> tickListBeen = new ArrayList<>();
    private List<Hotel.DataBean.HotelListBean> hotelListBeen = new ArrayList<>();
    private List<Holiday.DataBean.RouteListBean> routeListBeen = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        ButterKnife.bind(this);
        baiduMap = mapMapview.getMap();
        int type = getIntent().getIntExtra("type",0);
        switch (type){
            case 0:
                Scenic scenic = (Scenic) getIntent().getSerializableExtra("scenic");
                tickListBeen.addAll(scenic.getData().getTickList());
                for (int i = 0; i < tickListBeen.size(); i++) {
                    BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);
                    LatLng latlng = new LatLng(tickListBeen.get(i).getBaiduLatitude(), tickListBeen.get(i).getBaiduLongitude());
                    OverlayOptions opintions = new MarkerOptions().icon(bitmap).position(latlng);
                    baiduMap.addOverlay(opintions);
                }
                break;
            case 1:
                Hotel hotel = (Hotel) getIntent().getSerializableExtra("hotel");
                hotelListBeen.addAll(hotel.getData().getHotelList());
                for (int i = 0; i < hotelListBeen.size(); i++) {
                    BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);
                    LatLng latlng = new LatLng(hotelListBeen.get(i).getLatitude(), hotelListBeen.get(i).getLongitude());
                    OverlayOptions opintions = new MarkerOptions().icon(bitmap).position(latlng);
                    baiduMap.addOverlay(opintions);
                }
                break;
            case 2:

                break;

        }
    }


    @OnClick(R.id.iv_map_back)
    public void onClick() {
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapMapview.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapMapview.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapMapview.onDestroy();
    }

}
